package com.farm.learn.service.impl;

import com.farm.core.auth.domain.LoginUser;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.time.TimeTool;
import com.farm.learn.dao.ClassCommentDaoInter;
import com.farm.learn.domain.ClassComment;
import com.farm.learn.service.ClassCommentServiceInter;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ClassCommentServiceImpl implements ClassCommentServiceInter {
    @Resource
    private ClassCommentDaoInter classCommentDaoImpl;

    @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(ClassCommentServiceImpl.class);

    @Override
    @Transactional
    public ClassComment insertClassCommentEntity(ClassComment entity, LoginUser user) {
        entity.setCuser(user.getId());
        entity.setCtime(TimeTool.getTimeDate14());
        entity.setCusername(user.getName());
        entity.setPstate("1");
        return classCommentDaoImpl.insertEntity(entity);
    }

    @Override
    @Transactional
    public ClassComment editClassCommentEntity(ClassComment entity, LoginUser user) {

        ClassComment entity2 = classCommentDaoImpl.getEntity(entity.getId());
        entity2.setDescription(entity.getDescription());
        entity2.setClassid(entity.getClassid());
        entity2.setPstate(entity.getPstate());
        entity2.setCuser(entity.getCuser());
        entity2.setCusername(entity.getCusername());
        entity2.setCtime(entity.getCtime());
        entity2.setId(entity.getId());
        classCommentDaoImpl.editEntity(entity2);
        return entity2;
    }

    @Override
    @Transactional
    public void deleteClassCommentEntity(String id, LoginUser user) {

        classCommentDaoImpl.deleteEntity(classCommentDaoImpl.getEntity(id));
    }

    @Override
    @Transactional
    public ClassComment getClassCommentEntity(String id) {

        if (id == null) {
            return null;
        }
        return classCommentDaoImpl.getEntity(id);
    }

    @Override
    @Transactional
    public DataQuery createClassCommentSimpleQuery(DataQuery query) {

        DataQuery dbQuery = DataQuery
            .init(
                query,
                "WLP_L_COMMENT",
                "ID,DESCRIPTION,CLASSID,PSTATE,CUSER,CUSERNAME,CTIME");
        return dbQuery;
    }

    public ClassCommentDaoInter getClassCommentDaoImpl() {
        return classCommentDaoImpl;
    }

    public void setClassCommentDaoImpl(ClassCommentDaoInter dao) {
        this.classCommentDaoImpl = dao;
    }

}
